home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
A Field Trip to the Sky (Demo)
/
Mac_Sunburst_AFieldTripToTheSky-Demo.iso
/
DIR
/
TERMS.DIR
/
00019_Script_create terms text
< prev
next >
Wrap
Text File
|
1996-03-21
|
11KB
|
352 lines
-- ïï processTermFile ïï
-- create cast members from the term file
on zprocessTermFile theLetters, whichPhrase
set theFileName to the moviePath & theLetters & ".txt"
set theLineHgt to 14
if the machineType = 256 then
set theLineHgt to 17
end if
-- open the file and read it in
put fileio( mNew, "read", theFileName ) into theFile
if objectP(theFile) = TRUE then
put theFile(mReadFile) into theFileText
theFile(mDispose)
-- set up phrases
set thisPhrase to ""
set lastPhrase to ""
set phraseCount to 0
set numPhrases to 0
-- setup page cast
if the movieName contains "TERMS.DIR" then
set curPage to 1
set curC to createNewPageCast( theLetters, curPage )
end if
repeat with i = 1 to the number of lines of theFileText
set theLine to line i of theFileText
if charToNum(char 1 of theLine) = 10 then
set theLine to char 2 to length(theLine) of theLine
end if
set thisPhrase to getPhrase(theLine)
if thisPhrase <> "" then
if thisPhrase = lastPhrase then
set phraseCount to phraseCount + 1
else
set phraseCount to 1
end if
-- look ahead
if phraseCount = 1 AND whichPhrase = 2 then
set theLine2 to line i+1 of theFileText
if charToNum(char 1 of theLine2) = 10 then
set theLine2 to char 2 to length(theLine2) of theLine2
end if
if getPhrase(theLine2) <> thisPhrase then
set phraseCount = 2
end if
end if
-- add the cast member if we're on the right one
if phraseCount = whichPhrase then
put "ïï putting phrase '" & thisPhrase & "' into cast '" & the name of cast curC & "'"
-- create the cast member
set c to createTextCast(thisPhrase, theLine)
-- add it to the page if necessary
if the movieName contains "TERMS.DIR" then
-- is there an image?
set imageNum to the number of cast thisPhrase
if imageNum <> -1 then
set imageHgt to (the height of cast imageNum) + theLineHgt * 2 + 1
else
set imageHgt to 0
end if
set imageLines to imageHgt / theLineHgt
-- index everything
updateTermIndex( thisPhrase, the name of cast curC, numPhrases )
set numPhrases to numPhrases + 1
if curPage = 1 then
set pageLen to 17 * theLineHgt
else
set pageLen to 23 * theLineHgt
end if
if the machineType = 256 then
if curPage = 1 then
set pageLen to 14 * theLineHgt
else
set pageLen to 20 * theLineHgt
end if
end if
set nChars to length(field curC)
-- stick this text onto the page cast
put field c after field curC
set nNewWords to the number of words of field c
repeat while (the height of cast curC) > pageLen
set nNewWords to nNewWords - 1
delete word (the number of words of field curC) of field curC
end repeat
-- -- now add the carriage returns if we need room for a diagram
-- if the last word of field c contains "]" then
-- --put "adding cr ",the last word of field c
-- set t to 1
-- set theAddString to ""
-- repeat while t < 10 AND ((the height of cast curC) + t*theLineHgt) <= pageLen
-- set t to t + 1
-- set theAddString to theAddString & RETURN
-- end repeat
--
-- put theAddString after field curC
-- else
-- -- put "NOT adding cr ",the last word of field c
-- set t to 0
-- end if
-- boldify
set the textStyle of line (the number of lines of field curC) of field curC to "plain"
set the textstyle of char nChars+1 to nChars + length(thisPhrase) ¬
of field curC to "bold"
set the textStyle of char (nChars + length(thisPhrase) + 1) to length(field curC) ¬
of field curC to "plain"
-- stick in a cr if we fit everything on
if nNewWords = the number of words of field c then
put RETURN & RETURN after field curC
end if
-- if we've maxed out this page, create a new one
repeat while the height of cast curC >= pageLen then
set curPage to curPage + 1
set curC to createNewPageCast( theLetters, curPage )
-- stick in the rest
if nNewWords < (the number of words of field c) then
put " overflow...", (the number of words of field c) - nNewWords
set the text of cast curC to (word (nNewWords+1) to ¬
(the number of words of field c) of field c)
set nNewWords to (the number of words of field c)
end if
repeat while (the height of cast curC) > pageLen
set nNewWords to nNewWords - 1
delete word (the number of words of field curC) of field curC
end repeat
-- stick in a cr if we fit everything on
if (nNewWords = the number of words of field c) AND length(field curC) > 0 then
put RETURN & RETURN after field curC
end if
end repeat
-- lastly, check for picture
if imageLines <> 0 then
put " adding image " & thisPhrase
-- add a new page and pad it if we must
if (pageLen - the height of cast curC) <= (5 * imageHgt / 6) then
set curPage to curPage + 1
set curC to createNewPageCast( theLetters, curPage )
end if
-- if we can fit it + more text, add crs.
if( the height of cast curC + imageHgt < pageLen ) then
repeat with addcr = 1 to imageLines
put RETURN after field curC
end repeat
end if
end if
-- now add the carriage returns if we need room for a diagram
-- if t > 0 then
-- set theAddString to ""
-- repeat while t < 10 AND ((the height of cast curC) + t*theLineHgt) <= pageLen
-- set t to t + 1
-- set theAddString to theAddString & RETURN
-- end repeat
--
-- put theAddString after field curC
-- end if
end if -- we're on the right track
end if -- got a nonnull line
set lastPhrase to thisPhrase
end if
end repeat -- looping through lines of "abc.txt"
--make an evn number of text members
if (curPage mod 2) = 1 then
set curPage to curPage + 1
createNewPageCast( theLetters, curPage )
end if
else
alert "Error opening file" && theFileName && ":" && string(theFile)
end if
end
-- ïï getPhrase ïï
-- get the title of a definition line
on getPhrase theLine
set thePhrase to ""
if the number of words of theLine > 0 then
set o to offset(":", theLine)
set thePhrase to char 1 to (o-1) of theLine
end if
return thePhrase
end
-- ïï createTextCast ïï
on createTextCast thePhrase, theLine
set theCastName to thePhrase
-- does it exist?
if the movieName contains "TERMS.DIR" then
set c to 29
else
set c to 0
repeat with i = 30 to 249
if the castType of cast i = #text then
if the name of cast i = theCastName then
set c to i
exit repeat
end if
end if
end repeat
end if
-- it doesn't exist - create it
if c = 0 then
set c to findEmpty( cast 30 )
duplicate cast "template text", c
set the name of cast c to theCastName
end if
-- set it up
put theLine & " " into field c
set the textfont of field c to "palatino"
set the textstyle of field c to "plain"
set the textstyle of char 1 to length(thePhrase) of field c to "bold"
set the textStyle of char (length(thePhrase) + 1) to length(theLine) of field c to "plain"
delete char length(field c) of field c
put "createTextCast:" && QUOTE & theCastName & QUOTE && c, the height of cast c
return c
end
-- ïï createNewPageCast ïï
--
on createNewPageCast theLetters, theNum
set curC to 0
set theCastName to theLetters && "Page" && string(theNum)
set curC to the number of cast theCastName
if curC = -1 then
if theNum mod 2 = 1 then
put findEmpty( cast 132 ) into curC
duplicate cast "Page Template 2", curC
else
put findEmpty( cast 32 ) into curC
duplicate cast "Page Template 1", curC
end if
set the name of cast curC to theLetters && "Page" && string(theNum)
end if
put "createNewPageCast", curC, the name of cast curC
put " " into field curC
set the textStyle of field curC to "plain"
set the textFont of field curC to "palatino"
put "" into field curC
return curC
end
-- ïï updateTermIndex ïï
-- for each term, remember which page its on and get its audio file
on updateTermIndex theTerm, theTermPageName, numPhrases
set theText to the text of cast "Audio Files"
set smallC to the number of cast (theTerm && "info")
if smallC = -1 then
set smallC to findEmpty(cast 1400)
duplicate cast "abc index", smallC
set the name of cast smallC to (theTerm && "info")
end if
if theText contains (RETURN & theTerm & RETURN) then
set o to offset(RETURN & theTerm & RETURN, theText)
set o to o + length(theTerm) + 2
set theAudio to ""
repeat while char o of theText <> RETURN
set theAudio to theAudio & char o of theText
set o to o + 1
end repeat
end if
set theNumber to (the number of cast theTermPageName) - 31
set the text of cast smallC to theNumber && theAudio
end